package com.itheima.d2_buffered_stream;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;

public class chushibiao {
    public static void main(String[] args) {
        //将数据每一行放在list集合中
        ArrayList<String> contents = new ArrayList<>();
        //
        try (BufferedReader bf = new BufferedReader(new FileReader("day10io-app2/file/出师表.txt")
        )
        ) {
            String line;
            while ((line = bf.readLine()) != null) {
                contents.add(line);
            }
            Collections.sort(contents, (line1, line2) -> {
                //将每行的数字解析出来，按照数字的大小进行排序
//            String[] data = line1.split("\\.");
//            String numStr = data[0];
//            int num = Integer.parseInt(numStr);
                int n1 = Integer.parseInt(line1.split("\\.")[0]);
                int n2 = Integer.parseInt(line2.split("\\.")[0]);
                return Integer.compare(n1, n2);
            });
            contents.forEach(System.out::println);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try (BufferedWriter bw = new BufferedWriter(new FileWriter("day10io-app2/file/出师表2.txt"))) {
            for (String str : contents) {
                bw.write(str);
                bw.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
